package com.jrx.anytxn.transaction.mapper.ext;

import com.jrx.anytxn.transaction.entity.TlDisbursementLog;
import com.jrx.anytxn.transaction.mapper.base.TlDisbursementLogMapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 放款流水扩展
 * @author zhenghaopu
 * date: 2019/8/24 16:49
 */
public interface ExtTlDisbursementLogMapper extends TlDisbursementLogMapper {

    /**
     * 根据订单ID，渠道号和客户ID查询放款流水表信息
     * @param loanId     贷款id
     * @param customerId 客户id
     * @param tenantId   租户id
     * @return com.jrx.anytxn.transaction.entity.TlDisbursementLog
     * @author fan.yang
     * date: 2019/9/24 0024 下午 15:05
     */
    TlDisbursementLog selectDisbursementByCondition(@Param("loanId") String loanId, @Param("customerId") String customerId,
                                                    @Param("tenantId") String tenantId);

    /**
     * 批量-根据状态查询流水表
     * @param sumStatus 放款状态
     * @param grayVersion 灰度版本（P生产  G灰度）
     * @param queryMaxCounts 放款结果最大查询次数
     * @return
     */
    List<TlDisbursementLog> selectBySumStatus(@Param("sumStatus") String sumStatus,
                                              @Param("grayVersion") String grayVersion,
                                              @Param("queryMaxCounts") Integer queryMaxCounts);

    /**
     * 批量更新放款流水表（用于联机）
     *
     * @param updateLogList
     * @return
     */
    int batchUpdateLog(List<TlDisbursementLog> updateLogList);

    /**
     * 批量更新放款流水表（用于批量）
     * @param updateLogList
     * @return
     */
    int batchUpdateLogForBatch(List<TlDisbursementLog> updateLogList);


    int countDisbursementBySumStatusAndLoanId(@Param("loanId") String loanId, @Param("customerId") String customerId,
                                              @Param("tenantId") String tenantId,
                                              @Param(value = "statusList") List<String> statusList);

    /**
     * 根据流水号查询放款流水
     *
     * @param seqNo
     * @return
     */
    TlDisbursementLog selectBySeqNoAndTenantId(@Param("seqNo") String seqNo, @Param("tenantId") String tenantId);

    /**
     * 根据以下条件查询放款流水表信息
     * @param tenantId   租户ID
     * @param channel    渠道
     * @param customerId 客户ID
     * @param seqNo      流水号
     * @param beginDate  发起开始时间
     * @param endDate    发起结束时间
     * @return java.util.List<com.jrx.anytxn.transaction.entity.TlDisbursementLog>
     * @author fan.yang
     * date: 2020/7/30 0030 下午 16:04
     */
    List<TlDisbursementLog> selectByCondSelectivePage(@Param("tenantId") String tenantId, @Param("channel") String channel,
                                                      @Param("customerId") String customerId, @Param("seqNo") String seqNo,
                                                      @Param("beginDate") String beginDate, @Param("endDate") String endDate);

    /**
     * 根据以下条件查询放款流水信息
     * @param tenantId   租户ID
     * @param customerId 客户ID
     * @param seqNo      流水号
     * @return com.jrx.anytxn.transaction.entity.TlDisbursementLog
     * @author fan.yang
     * date: 2020/7/30 0030 下午 16:04
     */
    TlDisbursementLog selectTlDisbursementBySeqNoAndCusId(@Param("tenantId") String tenantId, @Param("customerId") String customerId, @Param("seqNo") String seqNo);


    int countByProductIdAndSumStatusAndBusinessDate(@Param("productId") String productId,
                                                    @Param("tenantId") String tenantId,
                                                    @Param("sumStatus") String sumStatus,
                                                    @Param("businessDate") Date businessDate);

    BigDecimal sumByProductIdAndSumStatusAndBusinessDate(@Param("productId") String productId,
                                                         @Param("tenantId") String tenantId,
                                                         @Param("sumStatus") String sumStatus,
                                                         @Param("businessDate") Date businessDate);

    List<TlDisbursementLog> selectByProductIdAndSumStatusAndBusDate(@Param("productId") String productId,
                                                                    @Param("tenantId") String tenantId,
                                                                    @Param("sumStatus") String sumStatus,
                                                                    @Param("businessDate") Date businessDate);

    void batchInsert(List<TlDisbursementLog> list);

    int countBySumStatusAndBusinessDate(@Param("tenantId") String tenantId,
                                        @Param("sumStatus") String sumStatus,
                                        @Param("businessDate") Date businessDate);

    BigDecimal sumBySumStatusAndBusinessDate(@Param("tenantId") String tenantId,
                                             @Param("sumStatus") String sumStatus,
                                             @Param("businessDate") Date businessDate);

    List<TlDisbursementLog> selectByTenantIdAndBusDate(@Param("tenantId") String tenantId,
                                                       @Param("businessDate") Date businessDate);

    List<TlDisbursementLog> selectByBusinessDate(@Param("businessDate") Date businessDate);

    /**
     * 根据sumStatus、cancleStatus查询  timer使用
     * @param sumStatus
     * @param cancleStatus
     * @return
     */
    List<TlDisbursementLog> selectBySumStatusAndCancleStatus(@Param("sumStatus") String sumStatus, @Param("cancleStatus") String cancleStatus);

    /**
     * 查询放款流水 timer使用
     * @param sumStatus      放款状态
     * @param cancelStatus   取消状态
     * @param cancelWhenFail 放款失败是否取消订单
     * @return List<TlDisbursementLog>
     */
    List<TlDisbursementLog> selectBySumStatusAndCancelStatusAndCancelWhenFail(@Param("sumStatus") String sumStatus,
                                                                              @Param("cancelStatus") String cancelStatus,
                                                                              @Param("cancelWhenFail") String cancelWhenFail,
                                                                              @Param("grayVersion") String grayVersion);

    /**
     * 根据订单ID，渠道号和客户ID查询放款流水表信息
     * @param loanId     贷款id
     * @param customerId 客户id
     * @param tenantId   租户id
     * @return com.jrx.anytxn.transaction.entity.TlDisbursementLog
     * @author fan.yang
     * date: 2019/9/24 0024 下午 15:05
     */
    List<TlDisbursementLog> selectBySumStatusAndLoanId(@Param("loanId") String loanId,
                                                       @Param("customerId") String customerId,
                                                       @Param("tenantId") String tenantId,
                                                       @Param("sumStatus") String sumStatus);

    void updateLog(TlDisbursementLog log);

    List<TlDisbursementLog> selectByBusinessDateAndChannel(@Param("businessDate") Date businessDate, @Param("channel") String channel);

    int countByBusinessDateAndChannel(@Param("businessDate") Date businessDate, @Param("channel") String channel);

    List<TlDisbursementLog> selectByBatch(@Param("channel") String channel, @Param("sumStatus") List<String> item, @Param("collateDate") Date collateDate);

    TlDisbursementLog selectByLoanIdAndSumStatuss(@Param("loanId") String loanId, @Param("customerId") String customerId,
                                                 @Param("tenantId") String tenantId,
                                                 @Param(value = "statusList") List<String> statusList);

    List<TlDisbursementLog> selectByCollateDate(@Param("collateDate") Date collateDate);

    /**
     * 查询正在支出中的借据
     * @param customerId
     * @param channel
     * @param tenantId
     * @param disbursementStatus
     * @param productIds
     * @return
     */
    List<TlDisbursementLog> selectUnderDisbursement(@Param("customerId") String customerId, @Param("channel") String channel, @Param("tenantId") String tenantId,
                                                    @Param("disbursementStatus") List<String> disbursementStatus, @Param("productIds") List<String> productIds);

    /**
     *
     * 查询日终T24核心汇总记账未记账放款记录
     * @param businessDate 业务日期
     * @param tenantId 租户id
     * @param productIds 产品列表
     * @param payeeAccountType 收款账户类型(0-本行，1-他行)
     * @param keepAccountStatusList 日终T24核心汇总记账状态 S-记账成功，F-记账失败，O-记账状态未知，默认空-未记账
     * @return
     */
    List<TlDisbursementLog> selectDailyT24NotAccountData(@Param("businessDate") Date businessDate,
                                                         @Param("tenantId") String tenantId,
                                                         @Param("productIds") List<String> productIds,
                                                         @Param("payeeAccountType") String payeeAccountType,
                                                         @Param("keepAccountStatusList") List<String> keepAccountStatusList);

    /**
     * 根据状态查询放款查询异常队列
     * @param queryParams 查询条件
     * @return
     */
    List<TlDisbursementLog> selectAbnormalQueueBySumStatus(TlDisbursementLog queryParams);

    /**
     * 更新当日进行退汇、抹账、取消等操作的订单
     * @param businessDate
     * @param tenantId
     */
    void updateCancelLogWithSameDate(@Param("tenantId") String tenantId, @Param("businessDate") Date businessDate);
}